rm(list=ls())

library(foreign)
library(ggplot2)
library(gridExtra)
library(grid)
library(lattice)
library(ggcorrplot)
library(ggrepel)

################# CONSERVATISM
setwd("")

diffdiffall<-read.dta("conservatism_clean.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.2)  

color.names<-c("black", "blue",  "purple", "darkgreen",  "red")

plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(Group, num)))+ 
  geom_rect(aes(xmin=-Inf, xmax=Inf, ymin=0, ymax=Inf), alpha=0.02, fill="red") +
  geom_rect(aes(xmin=-Inf, xmax=Inf, ymin=0, ymax=-Inf), alpha=0.02, fill="blue") +
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=1, alpha=0.7) +
  geom_hline(aes(yintercept=0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_point(data=diffdiffall, aes(colour=factor(Group), size=N)) + 
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour=factor(Group)),  width=0, size=1) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=22)) +
  scale_y_continuous(limits=c(-0.55, 0.55))+
  scale_size(range = c(2, 10)) +
  scale_colour_manual(values=color.names) + theme(legend.position="none") +
  labs(x="Subgroup", y="Coefficient Estimates (Standardized)", title="") +
  annotate("text", x=0.5, y= 0.275, label = "More Conservative", size=6.5, fontface="bold", colour="red", angle=90) +
  annotate("text", x=0.5, y = -0.275, label = "Less Conservative", size=6.5, fontface="bold", colour="blue", angle=90) + 
  annotate("text", x=5, y= 0.23, label = "Small Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=5, y = -0.23, label = "Small Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) + 
  annotate("text", x=5, y= 0.53, label = "Medium Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=5, y = -0.53, label = "Medium Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  geom_label(aes(y=-0.15, label=label_all),  size=5.35, fill="white", alpha=0.5) +
  theme(axis.text.y = element_text(angle = 90))

plot1
ggsave(plot1, file="conservatism.pdf", width=5, height=4, scale=2)


################# CONSERVATIVE POLICY -- ALL (no COHEN'S D LABELS BC THESE ARE IN PROBABILITY TERMS)
setwd("")

diffdiffall<-read.dta("conservative_policy_clean_all.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.2)  

color.names<-c("black", "blue",  "purple", "darkgreen",  "red")

plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(DV, num)))+ 
  geom_rect(aes(xmin=-Inf, xmax=Inf, ymin=0, ymax=Inf), alpha=0.02, fill="red") +
  geom_rect(aes(xmin=-Inf, xmax=Inf, ymin=0, ymax=-Inf), alpha=0.02, fill="blue") +
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=1, alpha=0.7) +
  geom_point(data=diffdiffall, aes(colour=factor(Group)), size=4) + 
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour=factor(Group)),  width=0, size=1) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=38)) +
  scale_y_continuous(limits=c(-0.55, 0.55))+
  scale_size(range = c(2, 10)) +
  scale_colour_manual(values=color.names) + theme(legend.position="none") +
  labs(x="Policy", y="Coefficient Estimates (Probability)", title="") +
  annotate("text", x=0.5, y= 0.275, label = "More Conservative", size=6.5, fontface="bold", colour="red", angle=90) +
  annotate("text", x=0.5, y = -0.275, label = "Less Conservative", size=6.5, fontface="bold", colour="blue", angle=90) +  
  theme(axis.text.y = element_text(angle = 90)) +
  theme(axis.text.x  = element_text(angle = 90))

plot1
ggsave(plot1, file="conservate_policy_all.pdf", width=13, height=6.5, scale=2)


################# CONSERVATIVE POLICY -- REPS  (no COHEN'S D LABELS BC THESE ARE IN PROBABILITY TERMS)
setwd("")

diffdiffall<-read.dta("conservative_policy_clean_republicans.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.2)  

color.names<-c("black", "blue",  "purple", "darkgreen",  "red")

plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(DV, num)))+ 
  geom_rect(aes(xmin=-Inf, xmax=Inf, ymin=0, ymax=Inf), alpha=0.02, fill="red") +
  geom_rect(aes(xmin=-Inf, xmax=Inf, ymin=0, ymax=-Inf), alpha=0.02, fill="blue") +
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=1, alpha=0.7) +
  geom_point(data=diffdiffall, aes(colour=factor(Group)), size=4) + 
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour=factor(Group)),  width=0, size=1) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=38)) +
  scale_y_continuous(limits=c(-0.55, 0.55))+
  scale_size(range = c(2, 10)) +
  scale_colour_manual(values=color.names) + theme(legend.position="none") +
  labs(x="Policy", y="Coefficient Estimates (Probability)", title="") +
  annotate("text", x=0.5, y= 0.275, label = "More Conservative", size=6.5, fontface="bold", colour="red", angle=90) +
  annotate("text", x=0.5, y = -0.275, label = "Less Conservative", size=6.5, fontface="bold", colour="blue", angle=90) +  
  theme(axis.text.y = element_text(angle = 90)) +
  theme(axis.text.x  = element_text(angle = 90))

plot1
ggsave(plot1, file="conservate_policy_republicans.pdf", width=13, height=6.5, scale=2)


################# CONSERVATIVE POLICY -- DEMS (no COHEN'S D LABELS BC THESE ARE IN PROBABILITY TERMS)
setwd("")

diffdiffall<-read.dta("conservative_policy_clean_democrats.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.2)  

color.names<-c("black", "blue",  "purple", "darkgreen",  "red")

plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(DV, num)))+ 
  geom_rect(aes(xmin=-Inf, xmax=Inf, ymin=0, ymax=Inf), alpha=0.02, fill="red") +
  geom_rect(aes(xmin=-Inf, xmax=Inf, ymin=0, ymax=-Inf), alpha=0.02, fill="blue") +
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=1, alpha=0.7) +
  geom_point(data=diffdiffall, aes(colour=factor(Group)), size=4) + 
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour=factor(Group)),  width=0, size=1) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=38)) +
  scale_y_continuous(limits=c(-0.55, 0.55))+
  scale_size(range = c(2, 10)) +
  scale_colour_manual(values=color.names) + theme(legend.position="none") +
  labs(x="Policy", y="Coefficient Estimates (Probability)", title="") +
  annotate("text", x=0.5, y= 0.275, label = "More Conservative", size=6.5, fontface="bold", colour="red", angle=90) +
  annotate("text", x=0.5, y = -0.275, label = "Less Conservative", size=6.5, fontface="bold", colour="blue", angle=90) + 
  theme(axis.text.y = element_text(angle = 90)) +
  theme(axis.text.x  = element_text(angle = 90))

plot1
ggsave(plot1, file="conservate_policy_democrats.pdf", width=13, height=6.5, scale=2)

################# CONSERVATIVE POLICY -- INDS  (no COHEN'S D LABELS BC THESE ARE IN PROBABILITY TERMS)
setwd("")

diffdiffall<-read.dta("conservative_policy_clean_independents.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.2)  

color.names<-c("black", "blue",  "purple", "darkgreen",  "red")

plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(DV, num)))+ 
  geom_rect(aes(xmin=-Inf, xmax=Inf, ymin=0, ymax=Inf), alpha=0.02, fill="red") +
  geom_rect(aes(xmin=-Inf, xmax=Inf, ymin=0, ymax=-Inf), alpha=0.02, fill="blue") +
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=1, alpha=0.7) +
  geom_point(data=diffdiffall, aes(colour=factor(Group)), size=4) + 
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour=factor(Group)),  width=0, size=1) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=38)) +
  scale_y_continuous(limits=c(-0.55, 0.55))+
  scale_size(range = c(2, 10)) +
  scale_colour_manual(values=color.names) + theme(legend.position="none") +
  labs(x="Policy", y="Coefficient Estimates (Probability)", title="") +
  annotate("text", x=0.5, y= 0.275, label = "More Conservative", size=8.5, fontface="bold", colour="red", angle=90) +
  annotate("text", x=0.5, y = -0.275, label = "Less Conservative", size=8.5, fontface="bold", colour="blue", angle=90) +
  theme(axis.text.y = element_text(angle = 90)) +
  theme(axis.text.x  = element_text(angle = 90))

plot1
ggsave(plot1, file="conservate_policy_independents.pdf", width=13, height=6.5, scale=2)


################ TRUMP APPROVAL

setwd("")

diffdiffall<-read.dta("incumbent_clean.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.2)  

color.names<-c("black", "blue",  "purple", "darkgreen",  "red")

plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(Group, num)))+ 
  geom_rect(aes(xmin=-Inf, xmax=Inf, ymin=0, ymax=Inf), alpha=0.02, fill="blue") +
  geom_rect(aes(xmin=-Inf, xmax=Inf, ymin=0, ymax=-Inf), alpha=0.02, fill="red") +
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=1, alpha=0.7) +
  geom_hline(aes(yintercept=0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_point(data=diffdiffall, aes(colour=factor(Group), size=N)) + 
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour=factor(Group)),  width=0, size=1) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=22)) +
  scale_y_continuous(limits=c(-0.55, 0.55))+
  scale_size(range = c(2, 10)) +
  scale_colour_manual(values=color.names) + theme(legend.position="none") +
  labs(x="Subgroup", y="Coefficient Estimates (Standardized)", title="") +
  annotate("text", x=0.5, y= 0.275, label = "More Disfavorable", size=6.5, fontface="bold", colour="blue", angle=90) +
  annotate("text", x=0.5, y = -0.275, label = "Less Disfavorable", size=6.5, fontface="bold", colour="red", angle=90) + 
  annotate("text", x=5, y= 0.23, label = "Small Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=5, y = -0.23, label = "Small Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) + 
  annotate("text", x=5, y= 0.53, label = "Medium Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=5, y = -0.53, label = "Medium Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  geom_label(aes(y=-0.15, label=label_all),  size=5.35, fill="white", alpha=0.5) +
  theme(axis.text.y = element_text(angle = 90))

plot1
ggsave(plot1, file="trump_approval.pdf", width=5, height=4, scale=2)


################ BIDEN APPROVAL

setwd("")

diffdiffall<-read.dta("challenger_clean.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.2)  

color.names<-c("black", "blue",  "purple", "darkgreen",  "red")

plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(Group, num)))+ 
  geom_rect(aes(xmin=-Inf, xmax=Inf, ymin=0, ymax=Inf), alpha=0.02, fill="red") +
  geom_rect(aes(xmin=-Inf, xmax=Inf, ymin=0, ymax=-Inf), alpha=0.02, fill="blue") +
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=1, alpha=0.7) +
  geom_hline(aes(yintercept=0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_point(data=diffdiffall, aes(colour=factor(Group), size=N)) + 
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour=factor(Group)),  width=0, size=1) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=22)) +
  scale_y_continuous(limits=c(-0.55, 0.55))+
  scale_size(range = c(2, 10)) +
  scale_colour_manual(values=color.names) + theme(legend.position="none") +
  labs(x="Subgroup", y="Coefficient Estimates (Standardized)", title="") +
  annotate("text", x=0.5, y= 0.275, label = "More Disfavorable", size=6.5, fontface="bold", colour="red", angle=90) +
  annotate("text", x=0.5, y = -0.275, label = "Less Disfavorable", size=6.5, fontface="bold", colour="blue", angle=90) + 
  annotate("text", x=5, y= 0.23, label = "Small Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=5, y = -0.23, label = "Small Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) + 
  annotate("text", x=5, y= 0.53, label = "Medium Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=5, y = -0.53, label = "Medium Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  geom_label(aes(y=-0.15, label=label_all),  size=5.35, fill="white", alpha=0.5) +
  theme(axis.text.y = element_text(angle = 90))

plot1
ggsave(plot1, file="biden_approval.pdf", width=5, height=4, scale=2)



################ RACIAL RESENTMENT

setwd("")

diffdiffall<-read.dta("racial_resentment.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.2)  

color.names<-c("black", "blue",  "purple", "darkgreen",  "red")

plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(Group, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=1, alpha=0.7) +
  geom_hline(aes(yintercept=0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_point(data=diffdiffall, aes(colour=factor(Group), size=N)) + 
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour=factor(Group)),  width=0, size=1) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=22)) +
  scale_y_continuous(limits=c(-0.55, 0.55))+
  scale_size(range = c(2, 10)) +
  scale_colour_manual(values=color.names) + theme(legend.position="none") +
  labs(x="Subgroup", y="Coefficient Estimates (Standardized)", title="") +
  annotate("text", x=0.5, y= 0.275, label = "Less Resentment", size=6.5, fontface="bold", colour="black", angle=90) +
  annotate("text", x=0.5, y = -0.275, label = "More Resentment", size=6.5, fontface="bold", colour="black", angle=90) + 
  geom_label(aes(y=-0.15, label=label_all),  size=5.35, fill="white", alpha=0.5) +
  annotate("text", x=5, y= 0.23, label = "Small Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=5, y = -0.23, label = "Small Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) + 
  annotate("text", x=5, y= 0.53, label = "Medium Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=5, y = -0.53, label = "Medium Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  theme(axis.text.y = element_text(angle = 90))

plot1
ggsave(plot1, file="racial_resentment.pdf", width=5, height=4, scale=2)


################ GENDER RESENTMENT

setwd("")

diffdiffall<-read.dta("gender_resentment.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.2)  

color.names<-c("black", "blue",  "purple", "darkgreen",  "red")

plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(Group, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=1, alpha=0.7) +
  geom_hline(aes(yintercept=0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_point(data=diffdiffall, aes(colour=factor(Group), size=N)) + 
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour=factor(Group)),  width=0, size=1) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=22)) +
  scale_y_continuous(limits=c(-0.55, 0.55))+
  scale_size(range = c(2, 10)) +
  scale_colour_manual(values=color.names) + theme(legend.position="none") +
  labs(x="Subgroup", y="Coefficient Estimates (Standardized)", title="") +
  annotate("text", x=0.5, y= 0.275, label = "More Resentment", size=6.5, fontface="bold", colour="black", angle=90) +
  annotate("text", x=0.5, y = -0.275, label = "Less Resentment", size=6.5, fontface="bold", colour="black", angle=90) + 
  geom_label(aes(y=-0.15, label=label_all),  size=5.35, fill="white", alpha=0.5) +
  annotate("text", x=5, y= 0.23, label = "Small Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=5, y = -0.23, label = "Small Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) + 
  annotate("text", x=5, y= 0.53, label = "Medium Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=5, y = -0.53, label = "Medium Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  theme(axis.text.y = element_text(angle = 90))

plot1
ggsave(plot1, file="gender_resentment.pdf", width=5, height=4, scale=2)


################# MAJORITY MINORITY DISFAVORABILITY-- ALL 
setwd("")

diffdiffall<-read.dta("majority_minority_groups_all.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.2)  

color.names<-c("black", "blue",  "purple", "darkgreen",  "red")

plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(DV, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=1, alpha=0.7) +
  geom_hline(aes(yintercept=0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_point(data=diffdiffall, aes(colour=factor(Group)), size=4) + 
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour=factor(Group)),  width=0, size=1) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=38)) +
  scale_y_continuous(limits=c(-0.55, 0.55))+
  scale_size(range = c(2, 10)) +
  scale_colour_manual(values=color.names) + theme(legend.position="none") +
  labs(x="Policy", y="Coefficient Estimates (Probability)", title="") +
  annotate("text", x=0.5, y= 0.275, label = "More Disfavorable", size=8.5, fontface="bold", colour="black", angle=90) +
  annotate("text", x=0.5, y = -0.275, label = "Less Disfavorable", size=8.5, fontface="bold", colour="black", angle=90) + 
  annotate("text", x=13, y= 0.23, label = "Small Cohen's d", size=6.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=13, y = -0.23, label = "Small Cohen's d", size=6.5, fontface="bold", colour="grey70", angle=0) + 
  annotate("text", x=13, y= 0.53, label = "Medium Cohen's d", size=6.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=13, y = -0.53, label = "Medium Cohen's d", size=6.5, fontface="bold", colour="grey70", angle=0) + 
  theme(axis.text.y = element_text(angle = 90)) +
  theme(axis.text.x  = element_text(angle = 90))

plot1
ggsave(plot1, file="majority_minority_all.pdf", width=13, height=6.5, scale=2)


################# MAJORITY MINORITY DISFAVORABILITY -- REPS 
setwd("")

diffdiffall<-read.dta("majority_minority_groups_republicans.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.2)  

color.names<-c("black", "blue",  "purple", "darkgreen",  "red")

plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(DV, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=1, alpha=0.7) +
  geom_hline(aes(yintercept=0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_point(data=diffdiffall, aes(colour=factor(Group)), size=4) + 
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour=factor(Group)),  width=0, size=1) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=38)) +
  scale_y_continuous(limits=c(-0.55, 0.55))+
  scale_size(range = c(2, 10)) +
  scale_colour_manual(values=color.names) + theme(legend.position="none") +
  labs(x="Policy", y="Coefficient Estimates (Probability)", title="") +
  annotate("text", x=0.5, y= 0.275, label = "More Disfavorable", size=8.5, fontface="bold", colour="black", angle=90) +
  annotate("text", x=0.5, y = -0.275, label = "Less Disfavorable", size=8.5, fontface="bold", colour="black", angle=90) + 
  annotate("text", x=13, y= 0.23, label = "Small Cohen's d", size=6.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=13, y = -0.23, label = "Small Cohen's d", size=6.5, fontface="bold", colour="grey70", angle=0) + 
  annotate("text", x=13, y= 0.53, label = "Medium Cohen's d", size=6.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=13, y = -0.53, label = "Medium Cohen's d", size=6.5, fontface="bold", colour="grey70", angle=0) +   
  theme(axis.text.y = element_text(angle = 90)) +
  theme(axis.text.x  = element_text(angle = 90))

plot1
ggsave(plot1, file="majority_minority_republicans.pdf", width=13, height=6.5, scale=2)


################# MAJORITY MINORITY DISFAVORABILITY -- DEMS 
setwd("")

diffdiffall<-read.dta("majority_minority_groups_democrats.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.2)  

color.names<-c("black", "blue",  "purple", "darkgreen",  "red")

plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(DV, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=1, alpha=0.7) +
  geom_hline(aes(yintercept=0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_point(data=diffdiffall, aes(colour=factor(Group)), size=4) + 
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour=factor(Group)),  width=0, size=1) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=38)) +
  scale_y_continuous(limits=c(-0.55, 0.55))+
  scale_size(range = c(2, 10)) +
  scale_colour_manual(values=color.names) + theme(legend.position="none") +
  labs(x="Policy", y="Coefficient Estimates (Probability)", title="") +
  annotate("text", x=0.5, y= 0.275, label = "More Disfavorable", size=8.5, fontface="bold", colour="black", angle=90) +
  annotate("text", x=0.5, y = -0.275, label = "Less Disfavorable", size=8.5, fontface="bold", colour="black", angle=90) + 
  annotate("text", x=13, y= 0.23, label = "Small Cohen's d", size=6.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=13, y = -0.23, label = "Small Cohen's d", size=6.5, fontface="bold", colour="grey70", angle=0) + 
  annotate("text", x=13, y= 0.53, label = "Medium Cohen's d", size=6.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=13, y = -0.53, label = "Medium Cohen's d", size=6.5, fontface="bold", colour="grey70", angle=0) + 
  theme(axis.text.y = element_text(angle = 90)) +
  theme(axis.text.x  = element_text(angle = 90))

plot1
ggsave(plot1, file="majority_minority_democrats.pdf", width=13, height=6.5, scale=2)

################# MAJORITY MINORITY DISFAVORABILITY -- INDS 
setwd("")

diffdiffall<-read.dta("majority_minority_groups_independents.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.2)  

color.names<-c("black", "blue",  "purple", "darkgreen",  "red")

plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(DV, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=1, alpha=0.7) +
  geom_hline(aes(yintercept=0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_point(data=diffdiffall, aes(colour=factor(Group)), size=4) + 
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour=factor(Group)),  width=0, size=1) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=38)) +
  scale_y_continuous(limits=c(-0.55, 0.55))+
  scale_size(range = c(2, 10)) +
  scale_colour_manual(values=color.names) + theme(legend.position="none") +
  labs(x="Policy", y="Coefficient Estimates (Probability)", title="") +
  annotate("text", x=0.5, y= 0.275, label = "More Disfavorable", size=8.5, fontface="bold", colour="black", angle=90) +
  annotate("text", x=0.5, y = -0.275, label = "Less Disfavorable", size=8.5, fontface="bold", colour="black", angle=90) + 
  annotate("text", x=13, y= 0.23, label = "Small Cohen's d", size=6.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=13, y = -0.23, label = "Small Cohen's d", size=6.5, fontface="bold", colour="grey70", angle=0) + 
  annotate("text", x=13, y= 0.53, label = "Medium Cohen's d", size=6.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=13, y = -0.53, label = "Medium Cohen's d", size=6.5, fontface="bold", colour="grey70", angle=0) + 
  theme(axis.text.y = element_text(angle = 90)) +
  theme(axis.text.x  = element_text(angle = 90))

plot1
ggsave(plot1, file="majority_minority_independents.pdf", width=13, height=6.5, scale=2)


################## IN OUT GROUPS GENDER
setwd("")

diffdiffall<-read.dta("gender_resentment_by_gender_clean.dta")

attach(diffdiffall) 

color.names<-c( "black",  "lightpink" , "lightblue")

plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(Group, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=1, alpha=0.7) +
  geom_hline(aes(yintercept=0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_point(data=diffdiffall, aes(colour=factor(Group)), size=8) + 
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour=factor(Group)),  width=0, size=1) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=24)) +
  scale_y_continuous(limits=c(-0.55, 0.55))+
  scale_size(range = c(2, 10)) +
  scale_colour_manual(values=color.names) + theme(legend.position="bottom") +
  labs(x="Subgroup", y="Coefficient Estimates (Standardized)", title="") +
  annotate("text", x=0.5, y= 0.275, label = "More Resentment", size=6.5, fontface="bold", colour="black", angle=90) +
  annotate("text", x=0.5, y = -0.275, label = "Less Resentment", size=6.5, fontface="bold", colour="black", angle=90) + 
  annotate("text", x=3.25, y= 0.23, label = "Small Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=3.25, y = -0.23, label = "Small Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) + 
  annotate("text", x=3.25, y= 0.53, label = "Medium Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=3.25, y = -0.53, label = "Medium Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) + 
  theme(axis.text.y = element_text(angle = 90)) +
  theme(legend.title= element_blank()) +  
  geom_label(aes(y=-0.15, label=label_all),  size=3, fill="white", alpha=0.5) 

plot1
ggsave(plot1, file="in_out_gender_group.pdf", width=4, height=4, scale=2)


################# IN OUT GROUPS RELIGION

setwd("")

diffdiffall<-read.dta("religion_by_religion_clean.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.8)  

plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(Group, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=1, alpha=0.7) +
  geom_hline(aes(yintercept=0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_point(data=diffdiffall, aes(colour=factor(DV)), size=8, position=pd) + 
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour=factor(DV)),  width=0, size=1, position=pd) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=24)) +
  scale_y_continuous(limits=c(-0.55, 0.55))+
  scale_size(range = c(2, 10)) + theme(legend.position="bottom") +
  labs(x="Subgroup", y="Coefficient Estimates (Standardized)", title="") +
  annotate("text", x=0.5, y= 0.275, label = "More Disfavorable", size=6.5, fontface="bold", colour="black", angle=90) +
  annotate("text", x=0.5, y = -0.275, label = "Less Disfavorable", size=6.5, fontface="bold", colour="black", angle=90) + 
  annotate("text", x=5, y= 0.23, label = "Small Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=5, y = -0.23, label = "Small Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) + 
  annotate("text", x=5, y= 0.53, label = "Medium Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=5, y = -0.53, label = "Medium Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) + 
  theme(axis.text.y = element_text(angle = 90)) +
  theme(legend.title= element_blank())+
  geom_label_repel(aes(label=label_all),  size=3, fill="white", alpha=0.5) 

plot1
ggsave(plot1, file="in_out_religion_group.pdf", width=5, height=4, scale=2)



################# IN OUT GROUPS RACE

setwd("")

diffdiffall<-read.dta("in_out_groups_cleaned.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.8)  

color.names<-c( "#9b870c",  "#3f000f" , "grey50")

plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(Group, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=1, alpha=0.7) +
  geom_hline(aes(yintercept=0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_point(data=diffdiffall, aes(colour=factor(DV)), size=8, position=pd) + 
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour=factor(DV)),  width=0, size=1, position=pd) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=24)) +
  scale_y_continuous(limits=c(-0.55, 0.55))+
  scale_size(range = c(2, 10)) +
  scale_colour_manual(values=color.names) + theme(legend.position="bottom") +
  labs(x="Subgroup", y="Coefficient Estimates (Standardized)", title="") +
  annotate("text", x=0.5, y= 0.275, label = "Less Resentment", size=6.5, fontface="bold", colour="black", angle=90) +
  annotate("text", x=0.5, y = -0.275, label = "More Resentment", size=6.5, fontface="bold", colour="black", angle=90) + 
  annotate("text", x=3.25, y= 0.23, label = "Small Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=3.25, y = -0.23, label = "Small Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) + 
  annotate("text", x=3.25, y= 0.53, label = "Medium Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=3.25, y = -0.53, label = "Medium Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) + 
  theme(axis.text.y = element_text(angle = 90)) +
  theme(legend.title= element_blank())+
  geom_label_repel(aes(label=label_all),  size=3, fill="white", alpha=0.5) 
  
plot1
ggsave(plot1, file="in_out_race_group.pdf", width=5, height=4, scale=2)


################# IN OUT GROUPS PARTY


setwd("")

diffdiffall<-read.dta("party_in_out_groups_clean.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.7)  

color.names<-c( "blue",  "red")

plot1<-ggplot(diffdiffall, aes(y=coef,  x=Group))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=1, alpha=0.7) +
  geom_hline(aes(yintercept=0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_point(data=diffdiffall, aes(colour=factor(DV)), size=8, position=pd) + 
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour=factor(DV)),  width=0, size=1, position=pd) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=12)) +
  scale_y_continuous(limits=c(-0.55, 0.55))+
  scale_size(range = c(2, 10)) +
  scale_colour_manual(values=color.names) + theme(legend.position="bottom") +
  labs(x="Subgroup", y="Coefficient Estimates (Standardized)", title="") +
  annotate("text", x=0.5, y= 0.275, label = "More Disfavorable", size=6.5, fontface="bold", colour="black", angle=90) +
  annotate("text", x=0.5, y = -0.275, label = "Less Disfavorable", size=6.5, fontface="bold", colour="black", angle=90) + 
  annotate("text", x=2.25, y= 0.23, label = "Small Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=2.25, y = -0.23, label = "Small Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) + 
  annotate("text", x=2.25, y= 0.53, label = "Medium Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=2.25, y = -0.53, label = "Medium Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) + 
  theme(axis.text.y = element_text(angle = 90)) +
  geom_label_repel(aes(label=label_all),  size=3, fill="white", alpha=0.5) +
  theme(legend.title= element_blank())

plot1
ggsave(plot1, file="in_out_party_group.pdf", width=4, height=4, scale=2)

############################ Summary of Effects - 20%

setwd("")

diffdiffall<-read.dta("all_dvs_spring_clean.dta")
attach(diffdiffall) 

color.names<-c( "grey50",  "black")

plot1<-ggplot(diffdiffall, aes(y=reorder(DV, DV_num),  x=reorder(Group, Group_num)))+ 
  geom_point(data=diffdiffall, aes(color=factor(sig), shape=factor(equivalence_cohen_small)), size=12, stroke = 2) +
  theme_bw() + theme( axis.line = element_line(colour = "black")) +
  scale_colour_manual(values=color.names) + theme(legend.position="bottom") +
  scale_shape_manual(values=c(16, 15))+
  labs(x="Subgroup", y="Outcomes", title="") +
  labs(shape="Rule out 20%?", colour="Statistically Significant?")+
  theme(text = element_text(size=22)) 
  
plot1
ggsave(plot1, file="effect_summary_20.pdf", width=8, height=10, scale=2)

############################ Summary of Effects - 10%

setwd("")

diffdiffall<-read.dta("all_dvs_spring_clean.dta")
attach(diffdiffall) 

color.names<-c( "grey50",  "black")

plot1<-ggplot(diffdiffall, aes(y=reorder(DV, DV_num),  x=reorder(Group, Group_num)))+ 
  geom_point(data=diffdiffall, aes(color=factor(sig), shape=factor(equivalence_10)), size=12, stroke = 2) +
  theme_bw() + theme( axis.line = element_line(colour = "black")) +
  scale_colour_manual(values=color.names) + theme(legend.position="bottom") +
  scale_shape_manual(values=c(16, 15))+
  labs(x="Subgroup", y="Outcomes", title="") +
  labs(shape="Rule out 10%?", colour="Statistically Significant?")+
  theme(text = element_text(size=22)) 

plot1
ggsave(plot1, file="effect_summary_10.pdf", width=8, height=10, scale=2)

############################ Summary of Effects - 20%

setwd("")

diffdiffall<-read.dta("all_dvs_spring_covs_clean.dta")
attach(diffdiffall) 

color.names<-c( "grey50",  "black")

plot1<-ggplot(diffdiffall, aes(y=reorder(DV, DV_num),  x=reorder(Group, Group_num)))+ 
  geom_point(data=diffdiffall, aes(color=factor(sig), shape=factor(equivalence_cohen_small)), size=12, stroke = 2) +
  theme_bw() + theme( axis.line = element_line(colour = "black")) +
  scale_colour_manual(values=color.names) + theme(legend.position="bottom") +
  scale_shape_manual(values=c(16, 15))+
  labs(x="Subgroup", y="Outcomes", title="") +
  labs(shape="Rule out 20%?", colour="Statistically Significant?")+
  theme(text = element_text(size=22)) 

plot1
ggsave(plot1, file="effect_summary_covs_20.pdf", width=8, height=10, scale=2)


############################ Summary of Effects - 10%

setwd("")

diffdiffall<-read.dta("all_dvs_spring_covs_clean.dta")
attach(diffdiffall) 

color.names<-c( "grey50",  "black")

plot1<-ggplot(diffdiffall, aes(y=reorder(DV, DV_num),  x=reorder(Group, Group_num)))+ 
  geom_point(data=diffdiffall, aes(color=factor(sig), shape=factor(equivalence_10)), size=12, stroke = 2) +
  theme_bw() + theme( axis.line = element_line(colour = "black")) +
  scale_colour_manual(values=color.names) + theme(legend.position="bottom") +
  scale_shape_manual(values=c(16, 15))+
  labs(x="Subgroup", y="Outcomes", title="") +
  labs(shape="Rule out 10%?", colour="Statistically Significant?")+
  theme(text = element_text(size=22)) 

plot1
ggsave(plot1, file="effect_summary_covs_10.pdf", width=8, height=10, scale=2)


############################ COVARIATE BALANCE
setwd("")

diffdiffall<-read.dta("covariatebalance_clean.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.2)  

plot1<-ggplot(diffdiffall, aes(y=coef,  x=DV))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=1, alpha=0.7) +
  geom_hline(aes(yintercept=0.1), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.1), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_point(data=diffdiffall, colour="black", size=4) + 
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr), colour="black",width=0, size=1) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=38)) +
  scale_y_continuous(limits=c(-0.55, 0.55))+
  scale_size(range = c(2, 10)) + theme(legend.position="none") +
  labs(x="Policy", y="Coefficient Estimates (Probability)", title="") +
  annotate("text", x=0.75, y= 0.275, label = "More in this Category", size=6.5, fontface="bold", colour="black", angle=90) +
  annotate("text", x=0.75, y = -0.275, label = "Fewer in this Category", size=6.5, fontface="bold", colour="black", angle=90) + 
  theme(axis.text.y = element_text(angle = 90)) +
  theme(axis.text.x  = element_text(angle = 90))

plot1
ggsave(plot1, file="covariatebalance.pdf", width=13, height=6.5, scale=2)


############################## DONUT RDD

setwd("")

diffdiffall<-read.dta("donut_clean.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.2)  

plot1<-ggplot(diffdiffall, aes(y=coef,  x=DV))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=1, alpha=0.7) +
  geom_hline(aes(yintercept=0.1), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.1), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_point(data=diffdiffall, colour="black", size=4) + 
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr), colour="black",width=0, size=1) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=38)) +
  scale_y_continuous(limits=c(-0.55, 0.55))+
  scale_size(range = c(2, 10)) + theme(legend.position="none") +
  labs(x="Policy", y="Coefficient Estimates", title="") +
  theme(axis.text.y = element_text(angle = 90)) +
  theme(axis.text.x  = element_text(angle = 90))

plot1
ggsave(plot1, file="donut.pdf", width=13, height=6.5, scale=2)



############################## DOW FE 

setwd("")

diffdiffall<-read.dta("dow_fe_clean.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.2)  

plot1<-ggplot(diffdiffall, aes(y=coef,  x=DV))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=1, alpha=0.7) +
  geom_hline(aes(yintercept=0.1), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.1), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_point(data=diffdiffall, colour="black", size=4) + 
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr), colour="black",width=0, size=1) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=38)) +
  scale_y_continuous(limits=c(-0.55, 0.55))+
  scale_size(range = c(2, 10)) + theme(legend.position="none") +
  labs(x="Policy", y="Coefficient Estimates", title="") +
  theme(axis.text.y = element_text(angle = 90)) +
  theme(axis.text.x  = element_text(angle = 90))

plot1
ggsave(plot1, file="dow_fe.pdf", width=13, height=6.5, scale=2)




############################## MONDAY TREAT

setwd("")

diffdiffall<-read.dta("all_dvs_spring_monday_clean_all.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.2)  

plot1<-ggplot(diffdiffall, aes(y=coef,  x=DV))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=1, alpha=0.7) +
  geom_hline(aes(yintercept=0.1), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.1), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_point(data=diffdiffall, colour="black", size=4) + 
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr), colour="black",width=0, size=1) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=38)) +
  scale_y_continuous(limits=c(-0.55, 0.55))+
  scale_size(range = c(2, 10)) + theme(legend.position="none") +
  labs(x="Policy", y="Coefficient Estimates", title="") +
  theme(axis.text.y = element_text(angle = 90)) +
  theme(axis.text.x  = element_text(angle = 90))

plot1
ggsave(plot1, file="monday_effect.pdf", width=13, height=6.5, scale=2)


############################ FALL 2019 Summary of Effects - 20%

setwd("")

diffdiffall<-read.dta("all_dvs_fall_2019_cleaned.dta")
attach(diffdiffall) 

color.names<-c( "grey50",  "black")

plot1<-ggplot(diffdiffall, aes(y=reorder(DV, DV_num),  x=reorder(Group, Group_num)))+ 
  geom_point(data=diffdiffall, aes(color=factor(sig), shape=factor(equivalence_cohen_small)), size=12, stroke = 2) +
  theme_bw() + theme( axis.line = element_line(colour = "black")) +
  scale_colour_manual(values=color.names) + theme(legend.position="bottom") +
  scale_shape_manual(values=c(16, 15))+
  labs(x="Subgroup", y="Outcomes", title="") +
  labs(shape="Rule out 20%?", colour="Statistically Significant?")+
  theme(text = element_text(size=22)) 

plot1
ggsave(plot1, file="effect_summary_20_fall.pdf", width=8, height=10, scale=2)

############################ FALL 2019: Summary of Effects - 10%

setwd("")

diffdiffall<-read.dta("all_dvs_fall_2019_cleaned.dta")
attach(diffdiffall) 

color.names<-c( "grey50",  "black")

plot1<-ggplot(diffdiffall, aes(y=reorder(DV, DV_num),  x=reorder(Group, Group_num)))+ 
  geom_point(data=diffdiffall, aes(color=factor(sig), shape=factor(equivalence_10)), size=12, stroke = 2) +
  theme_bw() + theme( axis.line = element_line(colour = "black")) +
  scale_colour_manual(values=color.names) + theme(legend.position="bottom") +
  scale_shape_manual(values=c(16, 15))+
  labs(x="Subgroup", y="Outcomes", title="") +
  labs(shape="Rule out 10%?", colour="Statistically Significant?")+
  theme(text = element_text(size=22)) 

plot1
ggsave(plot1, file="effect_summary_10_fall.pdf", width=8, height=10, scale=2)

############################ EVENT STUDY - SPRING WEEK BEFORE/AFTER
setwd("")

estimates <- list("event_study_sgroup_favorability_jews_clean", "event_study_sgroup_favorability_white_men_clean", "event_study_sgroup_favorability_lgbt_clean", "event_study_sgroup_favorability_undocumented_clean",
               "event_study_sgroup_favorability_the_police_clean", "event_study_sgroup_favorability_labor_unions_clean", "event_study_sgroup_favorability_muslims_clean",
               "event_study_sgroup_favorability_socialists_clean", "event_study_sgroup_favorability_evangelicals_clean", "event_study_sgroup_favorability_asians_clean", 
               "event_study_sgroup_favorability_latinos_clean", "event_study_sgroup_favorability_blacks_clean", "event_study_sgroup_favorability_whites_clean",
               "event_study_sgender_resentment_clean", "event_study_sracial_resentment_clean", "event_study_sgroup_favorability_republicans_clean", 
               "event_study_sgroup_favorability_democrats_clean", "event_study_scand_favorability_biden_clean", "event_study_scand_favorability_trump_clean", 
               "event_study_sconservatisim_clean", "event_study_sconservative_policy_clean", "event_study_c_limit_magazines_clean", "event_study_c_ban_assault_rifles_clean",
               "event_study_c_ban_guns_clean", "event_study_c_deportation_clean", "event_study_c_dreamers_clean", "event_study_c_path_to_citizenship_clean",
               "event_study_c_health_subsidies_clean", "event_study_c_public_option_clean", "event_study_c_gov_insurance_clean", "event_study_c_late_term_abortion_clean",
               "event_study_c_abortion_never_clean", "event_study_c_college_clean", "event_study_c_raise_upper_tax_clean", "event_study_c_estate_tax_clean",
               "event_study_c_guns_bg_clean", "event_study_c_cap_carbon_clean", "event_study_c_wall_clean")

i <- 1
for (i in 1:length(estimates)) {
  diffdiffall<-read.dta(paste0(estimates[[i]], ".dta"))

  plot1<-ggplot(diffdiffall, aes(y=coef,  x=center_day))+ 
    geom_point(data=diffdiffall, color="black", size=12) +
    geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr), color="black",  width=0, size=1) +
    scale_y_continuous(limits=c(-1, 1)) +
    geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=1, alpha=0.7) +
    geom_vline(aes(xintercept=-1), colour="black", linetype="dotted", size=1, alpha=0.7) +
    theme_bw() + theme( axis.line = element_line(colour = "black")) +
    labs(x="Days Since DST Began", y="Effect (Standardized)", title="") +
    theme(text = element_text(size=22))   +    scale_x_continuous(n.breaks = 15)
  
  plot1
  ggsave(plot1, file=paste0(estimates[[i]], ".pdf"), width=8, height=5, scale=2)
  print(i)
}

############################ Heatmap

setwd("")

datafull<-read.dta("nsALLCLEANDVS.dta")
attach(datafull) 


AxisLabs <- c("Conservatism", "Trump Disapproval", "Biden Disapproval", "White Disapproval", "Black Disapproval",
              "Latino Disapproval", "Asian Disapproval", "Evangelical Disapproval", "Socialists Disapproval", "Muslims Disapproval",
              "Union Disapproval", "Police Disapproval", "Undocumented Disapproval", "LGBT Disapproval", "White Men Disapproval", "Jewish Disapproval", 
              "Republican Disapproval", "Democrat Disapproval", "Racial Resentment", "Gender Resentment", "Policy: Border Wall", "Policy: Cap Carbon", 
              "Policy: Background Checks", "Policy: Estate Tax", "Policy: Upper Tax", "Policy: College Debt", "Policy: Abortion Never", "Policy: Late Abortion",
              "Policy: Govt Insurnace", "Policy: Public Option", "Policy: Health Subsidy", "Policy: Citizenship", "Policy: Dreamers", "Policy: Deportation", 
              "Policy: Ban Guns", "Policy: Ban Assault Rifle", "Policy: Limit Magazines", "Conservative Policy Scale")

cormat <- round(cor(datafull),2)

library(reshape2)
melted_cormat <- melt(cormat)
head(melted_cormat)

get_upper_tri <- function(cormat){
  cormat[lower.tri(cormat)]<- NA
  return(cormat)
}

upper_tri <- get_upper_tri(cormat)
melted_cormat <- melt(upper_tri, na.rm = TRUE)

corrmat<-ggplot(data = melted_cormat, aes(Var2, Var1, fill = value))+
  geom_tile(color = "white")+
  scale_fill_gradient2(low = "purple", high = "darkgreen", mid = "white", 
                       midpoint = 0, limit = c(-1,1), space = "Lab", 
                       name="Pearson\nCorrelation") +
  theme_minimal()+ 
  theme(axis.text.x = element_text(angle = 90, 
                                   size = 11))+
  labs(x="Variable 2", y="Variable 1", title="") +
  coord_fixed() + scale_x_discrete(labels= AxisLabs) + scale_y_discrete(labels= AxisLabs) +
  geom_hline(aes(yintercept=20.5), colour="grey50", linetype="solid", size=1, alpha=0.7) +
  geom_vline(aes(xintercept=20.5), colour="grey50", linetype="solid", size=1, alpha=0.7) 
  

corrmat
ggsave( "corrMAT.pdf", width=8, height=5, scale=2)


################# FACTOR SCALES
setwd("")

diffdiffall<-read.dta("two_dimensions_clean.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.2)  

color.names<-c("black", "#9b870c",  "#3f000f", "blue",  "purple", "darkgreen",  "red" , "grey50")


plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(Group, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=1, alpha=0.7) +
  geom_hline(aes(yintercept=0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_point(data=diffdiffall, aes(colour=factor(Group), size=N)) + 
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour=factor(Group)),  width=0, size=1) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(plot.title = element_text(hjust = 0.5)) +
  facet_grid(cols = vars(DV)) +
  theme(text = element_text(size=22)) +
  scale_y_continuous(limits=c(-0.55, 0.55))+
  scale_size(range = c(2, 10)) +
  scale_colour_manual(values=color.names) + theme(legend.position="none") +
  labs(x="Subgroup", y="Coefficient Estimates (Standardized)", title="") +
  annotate("text", x=8, y= 0.23, label = "Small Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=8, y = -0.23, label = "Small Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) + 
  annotate("text", x=8, y= 0.53, label = "Medium Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=8, y = -0.53, label = "Medium Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  geom_label(aes(y=-0.15, label=label_all),  size=5.35, fill="white", alpha=0.5) +
  theme(axis.text.y = element_text(angle = 90))

plot1
ggsave(plot1, file="factorscales.pdf", width=14, height=4, scale=2)



################# MEAN SCALES
setwd("")

diffdiffall<-read.dta("two_dimensions_mean_scales_clean.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.2)  

color.names<-c("black", "#9b870c",  "#3f000f", "blue",  "purple", "darkgreen",  "red" , "grey50")


plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(Group, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=1, alpha=0.7) +
  geom_hline(aes(yintercept=0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.2), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_hline(aes(yintercept=-0.5), colour="black", linetype="dotted", size=1, alpha=0.5) +
  geom_point(data=diffdiffall, aes(colour=factor(Group), size=N)) + 
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour=factor(Group)),  width=0, size=1) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(plot.title = element_text(hjust = 0.5)) +
  facet_grid(cols = vars(DV)) +
  theme(text = element_text(size=22)) +
  scale_y_continuous(limits=c(-0.55, 0.55))+
  scale_size(range = c(2, 10)) +
  scale_colour_manual(values=color.names) + theme(legend.position="none") +
  labs(x="Subgroup", y="Coefficient Estimates (Standardized)", title="") +
  annotate("text", x=8, y= 0.23, label = "Small Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=8, y = -0.23, label = "Small Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) + 
  annotate("text", x=8, y= 0.53, label = "Medium Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  annotate("text", x=8, y = -0.53, label = "Medium Cohen's d", size=4.5, fontface="bold", colour="grey70", angle=0) +
  geom_label(aes(y=-0.15, label=label_all),  size=5.35, fill="white", alpha=0.5) +
  theme(axis.text.y = element_text(angle = 90))

plot1
ggsave(plot1, file="meanscales.pdf", width=14, height=4, scale=2)

